import {createRouter, createWebHashHistory} from 'vue-router'
import {routes} from "./routes"
import useMemberStore from "@/store/modules/memberStore";

const router = createRouter({
    history: createWebHashHistory(import.meta.env.BASE_URL),
    routes: routes
})

//@ts-ignore
router.beforeEach((to, from, next) => {
    const memberStore = useMemberStore()
    if (to.meta.loginRequired) {
        if (memberStore.isLogin()) {
            next()
        } else {
            next("/login")
        }
    } else {
        next()
    }
})

export default router